﻿using System;
using CollegeSim.Domain.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CollegeSim.Domain.Test.Entities
{
    // Author: Ryan Redburn
    // Project: CollegeSim
    // Date: 2/18/2014

    #region [ Updates ]

    // Author: Ryan Redburn
    // Date: 5/13/2014
    // Revisions: Added Code tests.

    #endregion

    [TestClass]
    public class StudentTest
    {
        #region [ PersonID ]

        [TestMethod]
        public void PersonID_DefaultValue_EqualsExpected()
        {
            // Arrange
            var student = new Student();

            // Assert
            Assert.AreEqual(0, student.PersonID);
        }

        #endregion

        #region [ StudentID ]

        [TestMethod]
        public void StudentID_DefaultValue_EqualsExpected()
        {
            // Arrange
            var student = new Student();

            // Assert
            Assert.AreEqual(0, student.StudentID);
        }

        #endregion

        #region [ FirstName ]

        [TestMethod]
        public void FirstName_Empty_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.FirstName = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void FirstName_Nul_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.FirstName = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void FirstName_AboveLength_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.FirstName = "FirstName FirstName FirstName";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ LastName ]

        [TestMethod]
        public void LastName_Empty_ArgumentNullExecption()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.LastName = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void LastName_Null_ArgumentNullExecption()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {   
                // Act
                student.LastName = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void LastName_AboveLength_ArgumentOutOfRangeExecption()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.LastName = "LastName LastName LastName LastName";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ PhoneNumber ]

        [TestMethod]
        public void PhoneNumber_AboveLength_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.PhoneNumber = "PhoneNumber PhoneNumber";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ Email ]

        [TestMethod]
        public void Email_AboveLength_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.Email = "Email Email Email Email Email Email Email Email Email Email";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ Code ]

        [TestMethod]
        public void StudentCode_Empty_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.Code = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void StudentCode_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.Code = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void StudentCode_AboveLength_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.Code = "redburr1234";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void StudentCode_BelowLength_ArgumentOutOfRangeException()
        {
            var assert = false;
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            try
            {
                // Act
                student.Code = "redbur";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void StudentCode_Capitalization_UpperToLower()
        {
            // Arrange
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            // Act
            student.Code = "REDBURR";

            // Assert
            Assert.AreEqual("redburr", student.Code);
        }

        #endregion

        #region [ ToString() ]

        [TestMethod]
        public void StudentToString_ManualRepresentation_EqualsReturn()
        {
            // Arrange
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                Code = "redburr",
                EnrollmentDate = new DateTime(2013, 1, 4)
            };

            // Assert
            Assert.AreEqual(student.Code + " - " + student.LastName + ", " + student.FirstName + " - " + student.PhoneNumber, student.ToString());
        }

        #endregion
    }
}
